﻿#include "ToolTip.hpp"

ToolTip::ToolTip(QWidget* parent)
	:QWidget(parent)
{
	//setWindowFlags(Qt::Popup);
	setFocusPolicy(Qt::NoFocus);
	setWindowFlags(Qt::ToolTip);
	resize(100, 200);
	
}

void ToolTip::SetPromptMessage(QString haed, QString content)
{
	QLabel* label = new QLabel(haed, this);
	QSpacerItem* spacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum);//弹簧
	QHBoxLayout* hLayout = new QHBoxLayout(this);
	hLayout->addWidget(label);
	hLayout->addSpacerItem(spacer);


	QLabel* bottomLabel = new QLabel(content, this);
	QVBoxLayout* vLayout = new QVBoxLayout(this);
	vLayout->addLayout(hLayout);
	vLayout->addWidget(bottomLabel);

}

void ToolTip::showEvent(QShowEvent* event)
{
	if (parentWidget()) {
		// 计算窗口B的位置
		QPoint pos = parentWidget()->mapToGlobal(QPoint(0, parentWidget()->height()));
		int x = pos.x();
		int y = pos.y()+10;
		this->move(x, y);
	}
	QWidget::showEvent(event);
}
